package com.xhdx.thread;

public class RunnableTest {

    public static void main(String[] args) {
        Thread thread = new Thread(new Task());
        thread.start();

        Thread threadNew = new Thread(new Task());
        threadNew.start();
    }

}

class Task implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "-->" + i + "-->" + System.currentTimeMillis());
            /**线程礼让 yield,礼让线程，让当前正在执行的线程暂停，但不阻塞；
                                        将线程从运行状态转为就绪状态；让cpu重新调度，礼让不一定成功，看cpu心情**/
            Thread.yield();
            System.out.println(Thread.currentThread().getName() + "-->" + i + "-->" + System.currentTimeMillis());
            System.out.println("-----------------------------------------");
        }
    }

}